import type { CodeType, Patient, User, UserInfo } from '@/types/user.d'
import { request } from '@/utils/request'

/**
 * 密码登录
 * @param mobile 手机号
 * @param password 密码
 */
export const loginByPassword = (mobile: string, password: string) =>
  request<User>('/login/password', 'POST', { mobile, password })

/**
 * 获取短信验证码
 * @param mobile 手机号
 * @param type 验证码的作用类型
 */
export const sendMobileCode = (mobile: string, type: CodeType) =>
  request<{ code: string }>('/code', 'GET', { mobile, type })

/**
 * 短信登录
 * @param mobile 手机号
 * @param code 验证码
 */
export const loginByMobile = (mobile: string, code: string) =>
  request<User>('/login', 'POST', { mobile, code })

/**
 *获取个人中心数据
 */
export const getUserInfo = () => request<UserInfo>('/patient/myUser')

/**
 * 获取患者列表
 */
export const getPatientList = () => request<Patient[]>('/patient/mylist')

/**
 * 添加患者
 * @param patient 患者信息对象
 */
export const addPatient = (patient: Patient) =>
  request<{ id: string }>('/patient/add', 'POST', patient)

/**
 * 编辑患者
 * @param patient 患者信息对象
 */
export const editPatient = (patient: Patient) =>
  request<{ id: string }>('/patient/update', 'PUT', patient)

/**
 * 删除患者信息
 * @param id 患者的id
 */
export const delPatient = (id: string) =>
  request(`/patient/del/${id}`, 'DELETE')

/**
 * 查询患者详情
 * @param id 患者的id
 * @returns
 */
export const getPatientDetail = (id: string) =>
  request<Patient>(`/patient/info/${id}`)

/**
 * QQ三方登录
 * @param openId 用户身份唯一标识
 * @returns
 */
export const loginByQQ = (openId: string) =>
  request<User>('/login/thirdparty', 'POST', { openId, source: 'qq' })

/**
 * 绑定手机号
 * @param data
 * @returns
 */
export const bindMobile = (data: {
  mobile: string
  code: string
  openId: string
}) => request<User>('/login/binding', 'POST', data)
